require("lualib_bundle");
__TS__SourceMapTraceBack(debug.getinfo(1).short_src, {["4"] = 2,["5"] = 2,["6"] = 3,["7"] = 3,["8"] = 4,["9"] = 4,["10"] = 5,["11"] = 5,["12"] = 6,["13"] = 6,["14"] = 7,["15"] = 7,["16"] = 8,["17"] = 8,["18"] = 9,["19"] = 9,["20"] = 11,["21"] = 11,["22"] = 11,["24"] = 11,["25"] = 13,["26"] = 14,["27"] = 15,["28"] = 16,["29"] = 19,["30"] = 20,["31"] = 21,["32"] = 22,["33"] = 13,["34"] = 27,["35"] = 28,["36"] = 29,["37"] = 30,["38"] = 31,["39"] = 32,["40"] = 32,["41"] = 32,["42"] = 32,["43"] = 32,["44"] = 32,["45"] = 32,["46"] = 36,["47"] = 30,["48"] = 27,["49"] = 40,["50"] = 41,["51"] = 42,["52"] = 43,["53"] = 44,["54"] = 45,["55"] = 46,["56"] = 47,["57"] = 48,["58"] = 51,["59"] = 52,["60"] = 45,["61"] = 55,["62"] = 56,["63"] = 57,["64"] = 58,["65"] = 59,["66"] = 60,["67"] = 60,["68"] = 60,["69"] = 61,["70"] = 62,["71"] = 63,["72"] = 66,["73"] = 67,["74"] = 60,["75"] = 60,["76"] = 70,["77"] = 71,["78"] = 57,["79"] = 40,["80"] = 11});
local ____exports = {}
local ____trigger = require("solar.w3ts.handles.trigger")
local Trigger = ____trigger.Trigger
local ____BaseEntity = require("solar.ecs.BaseEntity")
local BaseEntity = ____BaseEntity.default
local ____UnitAttackedEventCom = require("solar.ecs.UnitAttackedEventCom")
local UnitAttackedEventCom = ____UnitAttackedEventCom.UnitAttackedEventCom
local ____unit = require("solar.w3ts.handles.unit")
local Unit = ____unit.Unit
local ____EntityDecaySystem = require("solar.ecs.EntityDecaySystem")
local EntityDecaySystem = ____EntityDecaySystem.default
local ____UpdateCom = require("solar.ecs.UpdateCom")
local UpdateCom = ____UpdateCom.default
local ____UnitCom = require("solar.ecs.UnitCom")
local UnitCom = ____UnitCom.default
local ____UnitSystem = require("solar.ecs.UnitSystem")
local UnitSystem = ____UnitSystem.default
____exports.default = __TS__Class()
local TriggerEvent2ECS = ____exports.default
TriggerEvent2ECS.name = "TriggerEvent2ECS"
function TriggerEvent2ECS.prototype.____constructor(self)
end
function TriggerEvent2ECS.init(self, world)
    local baseEntity = __TS__New(BaseEntity)
    baseEntity:add(__TS__New(UpdateCom, {}))
    world:addEntity(baseEntity)
    self:addUnitAttackedEvent(world)
    self:addUnitEnterMap(world)
    world:addSystem(__TS__New(UnitSystem))
    world:addSystem(__TS__New(EntityDecaySystem))
end
function TriggerEvent2ECS.addUnitAttackedEvent(self, world)
    local trigger = __TS__New(Trigger)
    trigger:registerAnyUnitEvent(EVENT_PLAYER_UNIT_ATTACKED)
    trigger:addAction(function()
        local baseEntity = __TS__New(BaseEntity, 10000)
        baseEntity:add(__TS__New(
            UnitAttackedEventCom,
            {
                attacker = Unit:fromHandle(GetAttacker()),
                attackedUnit = Unit:fromHandle(GetTriggerUnit())
            }
        ))
        world:addEntity(baseEntity)
    end)
end
function TriggerEvent2ECS.addUnitEnterMap(self, world)
    local trigger = __TS__New(Trigger)
    local rectRegion = CreateRegion()
    RegionAddRect(rectRegion, bj_mapInitialPlayableArea)
    trigger:registerEnterRegion(rectRegion, nil)
    trigger:addAction(function()
        local baseEntity = __TS__New(BaseEntity)
        local unit = Unit:fromHandle(GetTriggerUnit())
        baseEntity:add(__TS__New(UnitCom, {value = unit}))
        unit.entity = baseEntity
        world:addEntity(baseEntity)
    end)
    local onTimeTrigger = __TS__New(Trigger)
    onTimeTrigger:registerTimerEvent(0, false)
    onTimeTrigger:addAction(function()
        local groupHandle = CreateGroup()
        GroupEnumUnitsInRect(groupHandle, bj_mapInitialPlayableArea, nil)
        ForGroup(
            groupHandle,
            function()
                local baseEntity = __TS__New(BaseEntity)
                local unit = Unit:fromHandle(GetEnumUnit())
                baseEntity:add(__TS__New(UnitCom, {value = unit}))
                unit.entity = baseEntity
                world:addEntity(baseEntity)
            end
        )
        DestroyGroup(groupHandle)
        onTimeTrigger:destroy()
    end)
end
____exports.default = TriggerEvent2ECS
return ____exports
